package com.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.entity.Result;
import com.service.UserService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Reference
    private UserService userService;
    @RequestMapping("/getUsername")
    public Result getUsername(){
        try {
            User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            return new Result(true,"用户明查询成功",user.getUsername());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"用户明查询成功");
        }
    }
}
